package com.opass.cloud.server.autoconfigure.mybatis;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.opass.cloud.core.mybatis.DefaultEntityMetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * 配置类
 *
 * @author liuyadu
 */
@Slf4j
@Configuration
public class MybatisPlusAutoConfiguration {


    /**
     * 分页插件
     */
    @Bean
    @ConditionalOnMissingBean(PaginationInterceptor.class)
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        paginationInterceptor.setLimit(10000L);
        log.info("分页插件 [{}]", paginationInterceptor);
        return paginationInterceptor;
    }

    @Bean
    @Primary
    public DefaultEntityMetaObjectHandler entityMetaObjectHandler(){
        DefaultEntityMetaObjectHandler metaObjectHandler = new DefaultEntityMetaObjectHandler();
        log.info("实体自动填充类 [{}]", metaObjectHandler);
        return metaObjectHandler;
    }
}
